package com.bw.aop;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class MyAroudAOP {

    /**
     * 环绕通知  统计一下方法的执行耗时
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    @Around("execution(* com.bw.service.*.*(..))")
    public Object aop(ProceedingJoinPoint joinPoint) throws Throwable {

        System.out.println("方法名是 " + joinPoint.getSignature().getName()); // 获取 原方法的名字
        System.out.println("入参是 " + JSON.toJSONString(joinPoint.getArgs())); // 获取 原方法的入参

        long start = System.currentTimeMillis();

        Object proceed = joinPoint.proceed(); // 执行原方法

        long end = System.currentTimeMillis();
        System.out.println("方法的耗时 "  + (end -start));
        System.out.println("返回值是 " + JSON.toJSONString(proceed));
        return proceed;

    }

}
